#include "head_client.h"
extern flag_exit_by_client;
int commandSelect(char *command, char *path, int netfd, char *fileNameToUser)
{

    if (memcmp(command, "cd", 2) == 0)
    {
        puts("get command cd\n");
        train_t train;
        bzero(&train,sizeof(train));
        recvn(netfd,&train.length,sizeof(train.length));
        recvn(netfd,train.data,train.length);
        printf("command = %s\n",train.data);

    }
    else if (memcmp(command, "ls", 2) == 0)
    {
        train_ls_t train;
        puts("get command ls\n");
        bzero(&train, sizeof(train));
        recvn(netfd, &train.length, sizeof(train.length));
        recvn(netfd, train.data, train.length);
        printf("%s\n",train.data);
        //printf("test\n");
    }

    else if (memcmp(command, "gets", 4) == 0)
    {
        // train_t train;
        // bzero(&train,sizeof(train));
        // train.length = strlen("gets");
        // strcpy(train.data, "gets");
        // send(netfd, &train, sizeof(train.length) + train.length, MSG_NOSIGNAL);
        //puts("get command gets\n");
        recvFile(netfd, "unuse");
    }
    else if (memcmp(command, "puts", 4) == 0)
    {
        train_ls_t train;
        //puts("get command puts\n");
        bzero(&train, sizeof(train));
        //收自己发的文件名，文件名三期可能被改为MD5值
        recvn(netfd, &train.length, sizeof(train.length));
        recvn(netfd, train.data, train.length);

        transFile(netfd,"char *path", train.data);

    }
    else if (memcmp(command, "remove", 6) == 0)
    {
        train_t train;
        bzero(&train, sizeof(train));
        recvn(netfd, &train.length, sizeof(train.length));
        recvn(netfd, train.data, train.length);
        printf("%s\n",train.data);
        bzero(&train, sizeof(train));

        // recvn(netfd, &train.length, sizeof(train.length));
        // recvn(netfd, train.data, train.length);
        // printf("%s\n",train.data);

    }
    else if (memcmp(command, "pwd", 3) == 0)
    {
        //puts("get command pwd\n");
        train_t train;
        bzero(&train, sizeof(train));

        // 收文件名
        recvn(netfd, &train.length, sizeof(train.length));
        recvn(netfd, train.data, train.length);
        printf("%s\n",train.data);
    }
    else if (memcmp(command, "close", 5) == 0)
    {
        // train_t train;
        // bzero(&train,sizeof(train));
        // train.length = strlen("close");
        // strcpy(train.data, "close");
        // send(netfd, &train, sizeof(train.length) + train.length, MSG_NOSIGNAL);
        //puts("get command close\n");
        flag_exit_by_client = 1;
        // close(netfd);
        // goto end;
    }
    else if (memcmp(command, "mkdir", 5) == 0)
    {
        // train_t train;
        // bzero(&train,sizeof(train));
        // train.length = strlen("close");
        // strcpy(train.data, "close");
        // send(netfd, &train, sizeof(train.length) + train.length, MSG_NOSIGNAL);
        //puts("get command mkdir\n");
    }
    else
    {
        // 命令不合法
        //  train_t train;
        //  bzero(&train,sizeof(train));
        //  train.length = strlen("do not this command");
        //  strcpy(train.data, "do not this command");
        //  send(netfd, &train, sizeof(train.length) + train.length, MSG_NOSIGNAL);
        // 地址不合法
        puts("do not have this command\n");
    }
    return 0;
}